const config = require('../config')
import * as redis from 'redis';
const client = redis.createClient(config.REDIS.PORT, config.REDIS.HOST);
export default {
  /**
   * @description 操作redis，存储列表
   * @param {string} key 列表名
   * @param {*} value 数据
   */
  SetObjectData(key: string, value: any) {
    return new Promise((resolve, reject) => {
      client.set(key, value, (err, reply) => {
        if (err) {
          reject('Redis存储数据失败' + err);
        } else {
          console.log(reply);
          resolve(reply);
        }
      });
    });
  },
  /**
   * @description 操作redis，获取列表数据
   * @param {string} key 列表名
   * @param {*} value 数据 
   * @returns
   */
  getObjectDate(key: string) {
    
    return new Promise((resolve, reject) => {
      client.get(key, (err, data) => {
        if (err) {
          reject('Redis获取数据失败' + err);
        } else {
          console.log(data);
          resolve(data);
        }
      });
    });
  }
}